﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LiteExpress.Demo.Data;
using LiteExpress.Demo.Business.Models;
using LiteExpress.Demo.Business.Dto;

namespace LiteExpress.Demo.Business.Services
{
    public class UserService : IUserService
    {
        private IUserAdapter _userAdapter;

        public UserService(IUserAdapter userAdapter)
        {
            this._userAdapter = userAdapter;
        }
        

        public IEnumerable<UserModel> TestSql()
        {
            var entities = _userAdapter.TestSql();
            var result = entities.Select(d=>d.ToModel());
            return result;
        }

        public IEnumerable<UserModel> TestSqlMap()
        {
            var entities = _userAdapter.TestSqlMap();
            var result = entities.Select(d =>d.ToModel());
            return result;
        }

        public long InsertUser(UserModel model)
        {
            //ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validateret;
            //DataAnnotationsValidator.TryValidate(model, out validateret);

            var entity = model.ToEntity();
            var result = _userAdapter.Insert(entity);
            return result;
        }
    }
}
